package com.ludomancy.spaceopera.entities;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import com.ludomancy.gamelib.ImageStrip;
import com.ludomancy.gamelib.ResourceManager;
import com.ludomancy.spaceopera.BasicEntity;
import com.ludomancy.spaceopera.Game;
import com.ludomancy.spaceopera.LandWorld;
import com.ludomancy.spaceopera.Player;


public class Star extends BasicEntity
{
	private ImageStrip sprites;

	// planet classification
	public static final int CLIMATE_FROZEN = 0;
	public static final int CLIMATE_DRY = 1;
	public static final int CLIMATE_TEMPERATE = 2;
	public static final int CLIMATE_HOT = 3;
	public static final int CLIMATE_DESERTIC = 4;
	public static final int CLIMATE_RARE = 5;
	public static final int CLIMATES = 6;
	public int surface;

	public static final int PLANET_CLASS_GENERIC = 0;
	public static final int PLANET_CLASS_ARRAKIS = 1;
	public static final int PLANET_CLASS_ANARRES = 2;
	public static final int PLANET_CLASS_DOSADI = 3; // star blaster
	public static final int PLANET_CLASS_TERMINUS = 4; // seldon vault
	public static final int PLANET_CLASS_HARMONY = 5; // oversoul
	public static final int PLANET_CLASS_MAGRATHEA = 6; // improbability drive
	public static final int PLANET_CLASS_RIVERWORLD = 7; // cylinder
	public static final int PLANET_CLASS_TSACHI = 8; // memory
	public static final int PLANET_CLASS_ETERNIA = 9; // he-man espada
	public static final int PLANET_CLASS_KHARAK = 10; // hyperspace
	public static final int PLANET_CLASS_SOLARIS = 11; // ultimate happiness
	public static final int PLANET_CLASS_AIUR = 12; // xel naga's fury
	public static final int PLANET_CLASS_WINTER = 13; // ansible (communication)
	public static final int PLANET_CLASS_PANDORA = 14; // jesus incident
	public static final int PLANET_CLASS_WUNDERLAND = 15; // Reactionless Drive
	public static final int PLANET_CLASS_WEMADEIT = 16; // indestructible hull
	public static final int PLANET_CLASSES = 17; // indestructible hull
	
	public int planetClass;
		
	// size
	public static final int SIZE_SMALL = 0;
	public static final int SIZE_LARGE = 1;
	public int size;
	
	// landmass
	LandWorld planet = null;
	
	public Star(Point pos, int surface, int type, int size)
	{
		super(pos);
		this.planetClass = type;
		this.surface = surface;
		this.size = size;
		sprites = new ImageStrip(ResourceManager.getImage("stars.png"), 6, 6);
		width = (int) proj.screenToWorldX(sprites.frameWidth);
		height = (int) proj.screenToWorldY(sprites.frameHeight);
	}
	
	public String getInteractionVerb()
	{
		return "Land";
	}
	
	public boolean isInteractable()
	{
		return true;
	}
	
	public void paint(Graphics g, int x, int y)
	{
//		// debug
		if(isSpecial())
		{
			g.setColor(Color.RED);
			g.fillRect(x, y, 4, 4);
		}
		sprites.paint(g, surface + size*CLIMATES, x, y);
	}
	
	private LandWorld createPlanet()
	{
		if(planet == null)
		{
			planet = new LandWorld(this, Game.WORLD_WIDTH, Game.WORLD_HEIGHT);
			planet.push(new Landpad(Game.game.player.pos));
		}
		return planet;
	}
	
	public void onPlayerInteraction(Player player)
	{
		Game.game.landfall(createPlanet());
	}

	public void consume()
	{
		parent.add(new Explosion(new Point(pos)));
		parent.remove(this);
	}

	public boolean isSpecial()
	{
		return planetClass != PLANET_CLASS_GENERIC;
	}
}
